/* Exercice 5.41
   ejer5_41.c */
#include <stdio.h>
#include <math.h>

double distance(double x1, double y1, double x2, double y2);

/* function main begins program execution */
int main(void)
{
    double x1, x2, y1, y2;

    printf("Enter x1 and y1: ");
    scanf("%lf%lf", &x1, &y1);

    printf("Enter x2 and y2: ");
    scanf("%lf%lf", &x2, &y2);

    printf("The distance between (%0.2f, %0.2f) and (%0.2f, %0.2f) is: %0.4f\n",
           x1, y1,
           x2, y2,
           distance(x1, y1, x2, y2));

    return 0;
} /* end function main */

/* function distance, calculates the distance between two points (x1, y1) and (x2, y2) */
double distance(double x1, double y1, double x2, double y2)
{
    return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
} /* end function distancce */
